home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 2: CDPD 1 / Almathera Ten on Ten - Disc 2: CDPD 1.iso / pd / 201-225 / 204 / popinfo / popinfo.c < prev    next >
C/C++ Source or Header  |  1995-03-13  |  25KB  |  933 lines

  1. /* PopInfo v2.9 © Copyright 1989 Jonathan Potter
  2.  
  3.    Compiles with Manx C v3.6a - the makefile is included in the archive.
  4.  
  5.    This program is Public Domain - use it, don't abuse it.
  6.  
  7.    Jon. */
  8.  
  9. #include "PopInfo.h"
  10.  
  11. main(argc,argv)
  12. int argc;
  13. char *argv[];
  14. {
  15.     int message,code;
  16.     int wmess;
  17.     virusdesc[1]="  Not recognised as a virus.  ";
  18.     virusdesc[2]="    SCA virus recognised!!    ";
  19.     virusdesc[3]="BYTE BANDIT virus recognised!!";
  20.     virusdesc[4]="BYTE WARRIOR virus recognised!";
  21.     virusdesc[5]=" NORTHSTAR virus recognised!! ";
  22.     virusdesc[6]="  REVENGE virus recognised!!  ";
  23.     virusdesc[7]="  OBELISK virus recognised!!  ";
  24.     virusdesc[8]=" PENTAGON virus recognised!!! ";
  25.     virusdesc[9]=" SYSTEM Z virus recognised!!! ";
  26.     virusdesc[10]="    UF VIRUS recognised!!!    ";
  27.     virusdesc[11]="    HCS VIRUS recognised!!    ";
  28.     virusdesc[12]="DISK-DOKTOR VIRUS recognised!!";
  29.     virusdesc[13]="LAMER EX'TOR VIRUS recognised!";
  30.     virusdesc[14]=" ULTRAFOX VIRUS recognised!!  ";
  31.     virusdesc[15]=" GRAFFITI VIRUS recognised!!  ";
  32.     virusdesc[16]="16 BIT CREW VIRUS recognised!!";
  33.     virusdesc[17]=" PHANTASM VIRUS recognised!!  ";
  34.     virusdesc[18]="OLD N. STAR VIRUS recognised!!";
  35.     OpenAll();
  36.     KillMemory();
  37.     Window=(struct Window *) OpenWindow(&SWindow);
  38.     if (Window==NULL) CloseUp(10);
  39.     (void) SetTaskPri(FindTask((char *) 0), 20);
  40.     scr=Window->WScreen;
  41.     ScreenHeight=scr->Height;
  42.     checkbbs=0;
  43.     if (argc>=1 && (strncmp(argv[1],"-n",2))==0) checkbbs=1;
  44.     numdevs=countdevices();
  45.     oldtop=10; oldleft=0; oldw=639; oldh=50+(9*numdevs);
  46.     maxnumdevs=(ScreenHeight-50)/9;
  47.     onumdevs=numdevs;
  48.  
  49.     for(;;) {
  50.         waitaround:
  51.         if (((struct Window *) IntuitionBase->ActiveWindow)!=Window && flag==1
  52.                 && popflag==0) goto inactivate;
  53.         if (flag==1) OnGadget(&popstaygad,Window,NULL);
  54.         wmess=Wait(WINDOWMESSAGE | TIMERMESSAGE);
  55.         if (wmess&TIMERMESSAGE) {
  56.             Msg=GetMsg(TimerPort);
  57.             if (flag==1) goto partialrefresh;
  58.             TimeReq.tr_time.tv_secs=0;
  59.             TimeReq.tr_time.tv_micro=1000000;
  60.             SendIO((char *) &TimeReq.tr_node);
  61.             goto waitaround;
  62.         }
  63.         Msg=GetMsg(Window->UserPort);
  64.         message=Msg->Class;
  65.         code=Msg->Code;
  66.         ReplyMsg(Msg);
  67.         switch (message) {
  68.  
  69.             case CLOSEWINDOW:
  70.  
  71.                 CloseUp(0);
  72.  
  73.             case GADGETUP:
  74.  
  75.                 if (flag==1) {
  76.                     if (popflag==0) popflag=1;
  77.                     else popflag=0;
  78.                     goto waitaround;
  79.                 }
  80.                 flag=1;
  81.                 CloseWindow(Window);
  82.                 numdevs=countdevices();
  83.                 if (numdevs!=onumdevs) {
  84.                     if (oldh==(50+(9*onumdevs))) oldh=50+(9*numdevs);
  85.                     onumdevs=numdevs;
  86.                 }
  87.                 if (numdevs>maxnumdevs) numdevs=maxnumdevs;
  88.                 MWindow.TopEdge=oldtop;
  89.                 MWindow.LeftEdge=oldleft;
  90.                 MWindow.Width=oldw;
  91.                 MWindow.Height=oldh;
  92.                 MWindow.MaxHeight=50+(9*numdevs);
  93.                 if (oldh==(50+(9*onumdevs)))
  94.                     MWindow.Height=50+(9*numdevs);
  95.                 if (ScreenHeight-oldtop<50+(9*numdevs) && onumdevs!=numdevs)
  96.                     MWindow.TopEdge=(ScreenHeight-(50+(9*numdevs)));
  97.                 onumdevs=numdevs;
  98.                 Window=(struct Window *) OpenWindow(&MWindow);
  99.                 if (Window==NULL) CloseUp(10);
  100.                 SetWindowTitles(Window,-1,wintit);
  101.                 refreshwindow:
  102.                 sbbflag=0;
  103.                 cidcmp(0);
  104.                 OffGadget(&popstaygad,Window,NULL);
  105.                 SetAPen(iprint,0);
  106.                 RectFill(iprint,6,10,Window->Width-3,Window->Height-11);
  107.                 RectFill(iprint,17,Window->Height-10,Window->Width-17,Window->Height-2);
  108.                 SetAPen(iprint,3);
  109.                 mesg.FrontPen=3;
  110.                 sprintf(txt,"Unit Bytes     Used      Free      Ers WPS SBB Name");
  111.                 PrintIText(iprint,&mesg,-4,1);
  112.                 mesg.FrontPen=2;
  113.                 sprintf(txt,"____ _________ _________ _________ ___ ___ ___ ______________________________");
  114.                 PrintIText(iprint,&mesg,-4,2);
  115.                 mesg.FrontPen=1;
  116.                 y=12;
  117.                 Forbid();
  118.                 devlist=(struct DeviceList *) BADDR(dosinfo->di_DevInfo);
  119.                 while (devlist) {
  120.                     if (devlist->dl_Type!=DLT_DEVICE) {
  121.                         devlist=(struct DeviceList *) BADDR(devlist->dl_Next);
  122.                         continue;
  123.                     }
  124.                     conbstr((BPTR) devlist->dl_Name,devname);
  125.                     strcat(devname,":");
  126.                     if (devlist->dl_Task) {
  127.                         point1[0]=0;
  128.                         dnum=-1; nodisk=0; nondos=0; bbmess="N/A"; status="R/W";
  129.                         if (devname[0]==68 && devname[1]==70) dnum=devname[2]-48;
  130.                         if (dnum!=-1) {
  131.                             if (checkbbs==1) bbmess="N/C"; else bbmess="Yes";
  132.                             nodisk=diskpresent(dnum);
  133.                             if (nodisk==1) goto display;
  134.                             if (checkbbs!=1) {
  135.                                 ReadBlock(dnum);
  136.                                 point2=diskbuffer;
  137.                                 point1=diskbuffer;
  138.                                 if (point1[0]!=ID_DOS_DISK) {
  139.                                     nondos=2;
  140.                                     if (point1[0]==ID_UNREADABLE_DISK) nondos=1;
  141.                                     if (point1[0]==ID_KICKSTART_DISK) nondos=3;
  142.                                     goto display;
  143.                                 }
  144.                                 sum=0;
  145.                                 for (a=0;a<256;a++) {
  146.                                     lastsum=sum;
  147.                                     sum=sum+point2[a];
  148.                                     if (lastsum>sum) sum++;
  149.                                 }
  150.                                 if (sum!=0) {
  151.                                     nsbb[dnum]=0;
  152.                                     bbmess="NBB";
  153.                                     goto display;
  154.                                 }
  155.                                 point2=&diskbuffer[4];
  156.                                 for (x=0;x<39;x++) {
  157.                                     if (diskbuffer[x+8]!=bootblock[x+8]) {
  158.                                         nsbb[dnum]=1;
  159.                                         sbbflag=1;
  160.                                         bbmess="No";
  161.                                         break;
  162.                                     }
  163.                                 }
  164.                                 if ((CheckBlock(1))==FALSE) bbmess="VIR";
  165.                             }
  166.                         }
  167.                     display:
  168.                     if (nodisk==1) sprintf(txt,"%-4s No disk present in drive.", devname);
  169.                     else if (nondos==1)    sprintf(txt,"%-4s Unreadable disk.", devname);
  170.                     else if (nondos==2) sprintf(txt,"%-4s Not a DOS disk.", devname);
  171.                     else if (nondos==3)    sprintf(txt,"%-4s Kickstart disk.", devname);
  172.                     if (nodisk==0 && nondos==0) {
  173.                         if ((lock=Lock(devname,ACCESS_READ))==0) {
  174.                             nondos=1; goto display;
  175.                         }
  176.                         Info(lock,data);
  177.                         Examine(lock,finfo);
  178.                         if (data->id_DiskState==ID_VALIDATING)
  179.                             sprintf(txt,"%-4s Validating.", devname);
  180.                         else {
  181.                             volumename=finfo->fib_FileName;
  182.                             if ((strncmp(devname,"RAM:",4))==0 && volumename==NULL)
  183.                                 volumename="RAM Disk";
  184.                             if (data->id_DiskState==ID_WRITE_PROTECTED) status="R O";
  185.                             sprintf(txt,"%-4s %-9ld %-9ld %-9ld %-3ld %-3s %-3s %-30s",
  186.                                 devname,
  187.                                 data->id_BytesPerBlock*data->id_NumBlocks,
  188.                                 data->id_BytesPerBlock*data->id_NumBlocksUsed,
  189.                                 (data->id_BytesPerBlock*data->id_NumBlocks)-
  190.                                     (data->id_BytesPerBlock*data->id_NumBlocksUsed),
  191.                                 data->id_NumSoftErrors,
  192.                                 status,
  193.                                 bbmess,
  194.                                 volumename);
  195.                         }
  196.                     }
  197.                     PrintIText(iprint,&mesg,-4,y);
  198.                     if (nodisk==0 && nondos==0) {
  199.                         if (nsbb[dnum]>0) {
  200.                             sprintf(txt,"                                           %-3s",bbmess);
  201.                             if (nsbb[dnum]==1) mesg.FrontPen=2;
  202.                             else mesg.FrontPen=3;
  203.                             PrintIText(iprint,&mesg,-4,y);
  204.                             mesg.FrontPen=1;
  205.                             nsbb[dnum]=0;
  206.                         }
  207.                         UnLock(lock);
  208.                     }
  209.                     nondos=0; nodisk=0; dnum=0; y+=9;
  210.                 }
  211.             devlist=(struct DeviceList *) BADDR(devlist->dl_Next);
  212.             }
  213.             Permit();
  214.             fast=FASTMEMORY;
  215.             chip=CHIPMEMORY;
  216.             total=TOTALMEMORY;
  217.             DateStamp(&now);
  218.             hours=HOURS;
  219.             mins=MINS;
  220.             secs=SECS;
  221.             y+=5;
  222.             mesg.FrontPen=2;
  223.             sprintf(txt,"            FREE MEMORY      :             :             :");
  224.             PrintIText(iprint,&mesg,-4,y);
  225.             mesg.FrontPen=3;
  226.             sprintf(txt,"                         FAST          CHIP         TOTAL");
  227.            PrintIText(iprint,&mesg,-4,y);
  228.             mesg.FrontPen=1;
  229.             sprintf(txt,"                              %-7ld       %-6ld        %-7ld",
  230.                 fast,chip,total);
  231.             PrintIText(iprint,&mesg,-4,y);
  232.             mesg.FrontPen=3;
  233.             sprintf(txt,"                              TIME");
  234.             PrintIText(iprint,&mesg,-4,y+9);
  235.             mesg.FrontPen=2;
  236.             sprintf(txt,"                                      :  :");
  237.             PrintIText(iprint,&mesg,-4,y+9);
  238.             mesg.FrontPen=1;
  239.             sprintf(txt,"                                    %02d %02d %02d",
  240.                hours,mins,secs);
  241.             PrintIText(iprint,&mesg,-4,y+9);
  242.             RefreshGadgets(Window->FirstGadget,Window,NULL);
  243.             SizeWindow(Window,0,0);
  244.             OnGadget(&popstaygad,Window,NULL);
  245.             cidcmp(1);
  246.             goto waitaround;
  247.  
  248.             case RAWKEY:
  249.                 if (code!=0x40) goto waitaround;
  250.                 oldtop=Window->TopEdge;
  251.                 oldleft=Window->LeftEdge;
  252.                 oldh=Window->Height;
  253.                 oldw=Window->Width;
  254.                 SWindow.TopEdge=oldtop;
  255.                 SWindow.LeftEdge=oldleft;
  256.                 CloseWindow(Window);
  257.                 Window=(struct Window *) OpenWindow(&LWindow);
  258.                 ViewBoot(0);
  259.                 Window=(struct Window *) OpenWindow(&MWindow);
  260.                 if (Window==NULL) CloseUp(10);
  261.                 goto refreshwindow;
  262.  
  263.             case INACTIVEWINDOW:
  264.  
  265.                 inactivate:
  266.                 if (popflag==1) goto waitaround;
  267.                 if (flag==0) goto waitaround;
  268.                 flag=0;
  269.                 oldtop=Window->TopEdge;
  270.                 oldleft=Window->LeftEdge;
  271.                 oldh=Window->Height;
  272.                 oldw=Window->Width;
  273.                 CloseWindow(Window);
  274.                 SWindow.TopEdge=oldtop;
  275.                 SWindow.LeftEdge=oldleft;
  276.                 Window=(struct Window *) OpenWindow(&SWindow);
  277.                 if (Window==NULL) CloseUp(10);
  278.                 goto waitaround;
  279.  
  280.             case REFRESHWINDOW:
  281.  
  282.                 if (oldh!=Window->Height || oldw!=Window->Width) {
  283.                     numdevs=countdevices();
  284.                     WindowLimits(Window,0,0,0,(50+(9*numdevs)));
  285.                     oldh=Window->Height;
  286.                     oldw=Window->Width;
  287.                     goto refreshwindow;
  288.                 }
  289.                 goto waitaround;
  290.  
  291.             case DISKINSERTED:
  292.  
  293.                 if (flag==1)
  294.                     goto refreshwindow;
  295.                 goto waitaround;
  296.  
  297.             case DISKREMOVED:
  298.  
  299.                 if (flag==1) goto refreshwindow;
  300.                 goto waitaround;
  301.  
  302.             case MOUSEBUTTONS:
  303.  
  304.                 if (Msg->Code==MENUDOWN) goto refreshwindow;
  305.                 goto waitaround;
  306.  
  307.             default:
  308.             goto waitaround;
  309.         }
  310.  
  311.         partialrefresh:
  312.             RemoveGadget(Window,&popstaygad);
  313.             mesg.DrawMode=JAM2;
  314.             mesg.FrontPen=1;
  315.             fast=FASTMEMORY;
  316.             chip=CHIPMEMORY;
  317.             total=TOTALMEMORY;
  318.             DateStamp(&now);
  319.             hours=HOURS;
  320.             mins=MINS;
  321.             secs=SECS;
  322.             sprintf(txt,"%-7ld",fast);
  323.             PrintIText(iprint,&mesg,236,y);
  324.             sprintf(txt,"%-6ld",chip);
  325.             PrintIText(iprint,&mesg,348,y);
  326.             sprintf(txt,"%-7ld",total);
  327.             PrintIText(iprint,&mesg,460,y);
  328.             sprintf(txt,"%02d",hours);
  329.             PrintIText(iprint,&mesg,284,y+9);
  330.             sprintf(txt,"%02d",mins);
  331.             PrintIText(iprint,&mesg,308,y+9);
  332.             sprintf(txt,"%02d",secs);
  333.             PrintIText(iprint,&mesg,332,y+9);
  334.             mesg.DrawMode=JAM1;
  335.             AddGadget(Window,&popstaygad,-1);
  336.             TimeReq.tr_time.tv_secs=0;
  337.             TimeReq.tr_time.tv_micro=1000000;
  338.             SendIO((char *) &TimeReq.tr_node);
  339.             if (onumdevs!=countdevices()) {
  340.                 numdevs=countdevices();
  341.                 MWindow.MaxHeight=50+(9*numdevs);
  342.                 if (Window->Height==(50+(9*onumdevs)))
  343.                     MWindow.Height=50+(9*numdevs);
  344.                 if (ScreenHeight-oldtop<50+(9*numdevs) && onumdevs!=numdevs)
  345.                 MWindow.TopEdge=(ScreenHeight-(50+(9*numdevs)));
  346.                 if (Window->TopEdge+(50+(9*numdevs))>ScreenHeight) 
  347.                     MoveWindow(Window,0,(0-((Window->TopEdge)-(ScreenHeight-(50+(9*numdevs))))));
  348.                 SizeWindow(Window,0,((50+(9*numdevs))-(Window->Height))); 
  349.                 onumdevs=numdevs;
  350.                 goto refreshwindow;
  351.             }
  352.             onumdevs=countdevices();
  353.             goto waitaround;
  354.     }
  355. }
  356.  
  357. OpenAll()
  358. {
  359.     IntuitionBase=(struct IntuitionBase *) OpenLibrary("intuition.library",0);
  360.     if (IntuitionBase==NULL) CloseUp(20);
  361.     GfxBase=(struct GfxBase *) OpenLibrary("graphics.library",0);
  362.     if (GfxBase==NULL) CloseUp(25);
  363.     DosBase=(struct DosLibrary *) OpenLibrary("dos.library",0);
  364.     if (DosBase==NULL) CloseUp(30);
  365.     diskport=CreatePort(0,0);
  366.     if (diskport==NULL) CloseUp(35);
  367.     diskreq=CreateStdIO(diskport);
  368.     if (diskreq==NULL) CloseUp(40);
  369.     lock=(struct FileLock *) AllocMem(sizeof(struct FileLock),0);
  370.     if (lock==NULL) CloseUp(10);
  371.     data=(struct InfoData *) AllocMem(sizeof(struct InfoData),0);
  372.     if (data==NULL) CloseUp(10);
  373.     finfo=(struct FileInfoBlock *) AllocMem(sizeof(struct FileInfoBlock),0);
  374.     if (finfo==NULL) CloseUp(10);
  375.     TimerPort=CreatePort("Timer Port",0);
  376.     if (TimerPort==NULL) CloseUp(45);
  377.     error=OpenDevice("timer.device",UNIT_VBLANK,(char *) &TimeReq,0);
  378.     if (error!=NULL) CloseUp(50);
  379.     TimeReq.tr_node.io_Message.mn_ReplyPort=TimerPort;
  380.     TimeReq.tr_node.io_Command=TR_ADDREQUEST;
  381.     TimeReq.tr_node.io_Flags=0;
  382.     TimeReq.tr_node.io_Error=0;
  383.     TimeReq.tr_node.tv_secs=0;
  384.     TimeReq.tr_node.tv_micro=1000000;
  385.     SendIO((char *) &TimeReq.tr_node);
  386.     rootnode=(struct RootNode *) DosBase->dl_Root;
  387.     dosinfo-(struct DosInfo *) BADDR(rootnode->rn_Info);
  388. }
  389.  
  390. CloseUp(err)
  391. {
  392.     if (Window) CloseWindow(Window);
  393.     AbortIO((char *) &TimeReq.tr_node);
  394.     if (IntuitionBase) CloseLibrary(IntuitionBase);
  395.     if (GfxBase) CloseLibrary(GfxBase);
  396.     if (DosBase) CloseLibrary(DosBase);
  397.     CloseDevice(&TimeReq);
  398.     DeletePort(TimerPort);
  399.     DeletePort(diskport);
  400.     DeleteStdIO(diskreq);
  401.     OpenWorkBench();
  402.     if (err!=0) DisplayBeep(NULL);
  403.     exit(err);
  404. }
  405.  
  406. conbstr(in,out)
  407. BSTR in;
  408. char *out;
  409. {
  410.     register UBYTE *ch;
  411.     register int len,i;
  412.     ch=(UBYTE *) BADDR(in);
  413.     len=(int) *(ch++);
  414.     len=(len>20)?20:len;
  415.     for (i=0;i<len;i++) out[i]=*(ch++);
  416.     out[i]='\0';
  417. }
  418.  
  419. countdevices()
  420. {
  421.     int devices;
  422.     devices=0;
  423.     Forbid();
  424.     rootnode=(struct RootNode *) DosBase->dl_Root;
  425.     dosinfo=(struct DosInfo *) BADDR(rootnode->rn_Info);
  426.     devlist=(struct DeviceList *) BADDR(dosinfo->di_DevInfo);
  427.     while (devlist) {
  428.         if (devlist->dl_Type!=NULL) {
  429.             devlist=(struct DeviceList *) BADDR(devlist->dl_Next);
  430.             continue;
  431.         }
  432.         if (DLT_DEVICE!=NULL || devlist->dl_Task) ++devices;
  433.         devlist=(struct DeviceList *) BADDR(devlist->dl_Next);
  434.     }
  435.     Permit();
  436.     return(devices);
  437. }
  438.  
  439. diskpresent(drive)
  440. int drive;
  441. {
  442.     int nd;
  443.     nd=0;
  444.     error=OpenDevice("trackdisk.device",drive,diskreq,0);
  445.     diskreq->io_Command=TD_CHANGESTATE;
  446.     DoIO(diskreq);
  447.     if (diskreq->io_Actual!=0) nd=1;
  448.     CloseDevice(diskreq);
  449.     return(nd);
  450. }
  451.  
  452. ReadBlock(drive)
  453. int drive;
  454. {
  455.     int l;
  456.     for (l=0;l<1024;l++) diskbuffer[l]=0;
  457.     error=OpenDevice("trackdisk.device",drive,diskreq,0);
  458.     diskreq->io_Command=CMD_READ;
  459.     diskreq->io_Data=diskbuffer;
  460.     diskreq->io_Length=1024;
  461.     diskreq->io_Offset=0;
  462.     DoIO(diskreq);
  463.     diskreq->io_Length=0;
  464.     diskreq->io_Command=TD_MOTOR;
  465.     DoIO(diskreq);
  466.     CloseDevice(diskreq);
  467. }
  468.  
  469. cidcmp(state)
  470. int state;
  471. {
  472.     if (state==0) {
  473.         ModifyIDCMP(Window,NULL);
  474.         return();
  475.     }
  476.     ModifyIDCMP(Window,CLOSEWINDOW|INACTIVEWINDOW|GADGETUP|DISKINSERTED|
  477.         RAWKEY|DISKREMOVED|REFRESHWINDOW|MOUSEBUTTONS);
  478.     return();
  479. }
  480.  
  481. ViewBoot(c)
  482. int c;
  483. {
  484.     struct Gadget *gad;
  485.     int q, gadgetid, block;
  486.     CheckDriveGadgets();
  487.     nsbb[c]=0;
  488.     y=0;
  489.     ReadBlock(c);
  490.     DisplayBoot(0); block=0; blktext.IText="BLK1"; CheckBlock();
  491.     RefreshGadgets(&blkgadget,Window,NULL);
  492.     for (;;) {
  493.         Wait(1<<Window->UserPort->mp_SigBit);
  494.         while (Msg=GetMsg(Window->UserPort)) {
  495.             ReplyMsg(Msg);
  496.             gad=(struct Gadget *) Msg->IAddress;
  497.             gadgetid=gad->GadgetID;
  498.             switch (gadgetid) {
  499.                 case EXIT:
  500.                     CloseWindow(Window);
  501.                     return(FALSE);
  502.                     break;
  503.                 case BLK:
  504.                     if (block==0) block=1; else block=0;
  505.                     if (block==1) blktext.IText="BLK0"; else blktext.IText="BLK1";
  506.                     RefreshGadgets(&blkgadget,Window,NULL);
  507.                     DisplayBoot(block);
  508.                     break;
  509.                 case DF0:
  510.                     ReadBlock(0); c=0;
  511.                     DisplayBoot(0); block=0; blktext.IText="BLK1";
  512.                     RefreshGadgets(&blkgadget,Window,NULL);
  513.                     CheckBlock();
  514.                     break;
  515.                 case DF1:
  516.                     ReadBlock(1); c=1;
  517.                     DisplayBoot(0); block=0; blktext.IText="BLK1"; 
  518.                     RefreshGadgets(&blkgadget,Window,NULL);
  519.                     CheckBlock();
  520.                     break;
  521.                 case DF2:
  522.                     ReadBlock(2); c=2;
  523.                     DisplayBoot(0); block=0; blktext.IText="BLK1"; 
  524.                     RefreshGadgets(&blkgadget,Window,NULL);
  525.                     CheckBlock();
  526.                     break;
  527.                 case DF3:
  528.                     ReadBlock(3); c=3;
  529.                     DisplayBoot(0); block=0; blktext.IText="BLK1"; 
  530.                     RefreshGadgets(&blkgadget,Window,NULL);
  531.                     CheckBlock();
  532.                     break;
  533.                 case WIPE:
  534.                     WipeBoot(c);
  535.                     ReadBlock(c);
  536.                     DisplayBoot(0); block=0; blktext.IText="BLK1"; 
  537.                     RefreshGadgets(&blkgadget,Window,NULL);
  538.                     CheckBlock();
  539.                     break;
  540.                 case SAVE:
  541.                     SaveBoot();
  542.                     break;
  543.                 case LOAD:
  544.                     LoadBoot(c);
  545.                     ReadBlock(c);
  546.                     DisplayBoot(0); block=0; blktext.IText="BLK1";
  547.                     RefreshGadgets(&blkgadget,Window,NULL);
  548.                     CheckBlock();
  549.                     break;
  550.                 default:
  551.                     break;
  552.             }
  553.         }
  554.     }
  555. }
  556.  
  557. DisplayBoot(which)
  558. int which;
  559. {
  560.     int a,s;
  561.     if (which==0) a=0; else a=512; s=a;
  562.     SetAPen(iprint,0);
  563.     RectFill(iprint,5,2,579,140);
  564.     RectFill(iprint,5,130,637,198);
  565.     SetAPen(iprint,1);
  566.     for (y=-9;y<=111;y=y+8) {
  567.         sprintf(txt,"%02x%02x%02x%02x %02x%02x%02x%02x %02x%02x%02x%02x %02x%02x%02x%02x",
  568.             diskbuffer[a],diskbuffer[a+1],diskbuffer[a+2],
  569.             diskbuffer[a+3],diskbuffer[a+4],diskbuffer[a+5],
  570.             diskbuffer[a+6],diskbuffer[a+7],diskbuffer[a+8],
  571.             diskbuffer[a+9],diskbuffer[a+10],diskbuffer[a+11],
  572.             diskbuffer[a+12],diskbuffer[a+13],diskbuffer[a+14],
  573.             diskbuffer[a+15]);
  574.         PrintIText(iprint,&mesg,0,y);
  575.         sprintf(txt,"%02x%02x%02x%02x %02x%02x%02x%02x %02x%02x%02x%02x %02x%02x%02x%02x",
  576.             diskbuffer[a+16],diskbuffer[a+17],diskbuffer[a+18],
  577.             diskbuffer[a+19],diskbuffer[a+20],diskbuffer[a+21],
  578.             diskbuffer[a+22],diskbuffer[a+23],diskbuffer[a+24],
  579.             diskbuffer[a+25],diskbuffer[a+26],diskbuffer[a+27],
  580.             diskbuffer[a+28],diskbuffer[a+29],diskbuffer[a+30],
  581.             diskbuffer[a+31]);
  582.         PrintIText(iprint,&mesg,288,y);
  583.         a+=32;
  584.     }
  585.     Move(iprint,10,140);
  586.     Text(iprint,&diskbuffer[s],78);
  587.     Move(iprint,10,149);
  588.     Text(iprint,&diskbuffer[s+78],78);
  589.     Move(iprint,10,158);
  590.     Text(iprint,&diskbuffer[s+156],78);
  591.     Move(iprint,10,167);
  592.     Text(iprint,&diskbuffer[s+234],78);
  593.     Move(iprint,10,176);
  594.     Text(iprint,&diskbuffer[s+312],78);
  595.     Move(iprint,10,185);
  596.     Text(iprint,&diskbuffer[s+390],78);
  597.     Move(iprint,141,194);
  598.     Text(iprint,&diskbuffer[s+468],44);
  599. }
  600.  
  601. WipeBoot(c)
  602. int c;
  603. {
  604.     error=YesNo(" Really install this disk?");
  605.     if (error==FALSE) return();
  606.     error=OpenDevice("trackdisk.device",c,diskreq,0);
  607.     tryagain:
  608.     diskreq->io_Command=TD_PROTSTATUS;
  609.     DoIO(diskreq);
  610.     if (diskreq->io_Actual!=0) {
  611.         error=YesNo(" Disk is write protected!!");
  612.         if (error==TRUE) goto tryagain;
  613.         CloseDevice(diskreq);
  614.         return();
  615.     }
  616.     for (x=0;x<1024;x++)
  617.         diskbuffer[x]=0;
  618.     CopyMem(bootblock,diskbuffer,50);
  619.     diskreq->io_Length=1024;
  620.     diskreq->io_Data=&diskbuffer[0];
  621.     diskreq->io_Command=CMD_WRITE;
  622.     diskreq->io_Offset=0;
  623.     DoIO(diskreq);
  624.     diskreq->io_Command=CMD_UPDATE;
  625.     DoIO(diskreq);
  626.     diskreq->io_Command=TD_MOTOR;
  627.     diskreq->io_Length=0;
  628.     DoIO(diskreq);
  629.     nsbb[dnum]=0;
  630.     return();
  631. }
  632.  
  633. SaveBoot()
  634. {
  635.     opensavefile:
  636.     filename=gf("Enter filename for Save",170,70);
  637.     if (filename==NULL) return();
  638.     bbsavefile=fopen(filename,"w");
  639.     if (bbsavefile==NULL) {
  640.         error=YesNo("Can't open specified file!!");
  641.         if (error==FALSE) return();
  642.         goto opensavefile;
  643.     }
  644.     for (x=0;x<1024;x++)
  645.     putc(diskbuffer[x],bbsavefile);
  646.     fclose(bbsavefile);
  647.     return();
  648. }
  649.  
  650. LoadBoot(unit)
  651. int unit;
  652. {
  653.     char c;
  654.     int x;
  655.  
  656.     openloadfile:
  657.     filename=gf("Enter filename for Load",170,70);
  658.     if (filename==NULL) return();
  659.     bbsavefile=fopen(filename,"r");
  660.     if (bbsavefile==NULL) {
  661.         error=YesNo("Can't open specified file!!");
  662.         if (error==FALSE) return();
  663.         goto openloadfile;
  664.     }
  665.     for (x=0;x<1024;x++)
  666.         diskbuffer[x]=getc(bbsavefile);
  667.     fclose(bbsavefile);
  668.     error=OpenDevice("trackdisk.device",unit,diskreq,0);
  669.     tryagain:
  670.     diskreq->io_Command=TD_PROTSTATUS;
  671.     DoIO(diskreq);
  672.     if (diskreq->io_Actual!=0) {
  673.         error=YesNo(" Disk is write protected!!");
  674.         if (error==TRUE) goto tryagain;
  675.         CloseDevice(diskreq);
  676.         return();
  677.     }
  678.     error=YesNo("  Really write bootblock?");
  679.     if (error==FALSE) {
  680.         CloseDevice(diskreq);
  681.         return();
  682.     }
  683.     diskreq->io_Length=1024;
  684.     diskreq->io_Data=&diskbuffer[0];
  685.     diskreq->io_Command=CMD_WRITE;
  686.     diskreq->io_Offset=0L;
  687.     DoIO(diskreq);
  688.     diskreq->io_Command=CMD_UPDATE;
  689.     DoIO(diskreq);
  690.     diskreq->io_Length=0;
  691.     diskreq->io_Command=TD_MOTOR;
  692.     DoIO(diskreq);
  693.     CloseDevice(diskreq);
  694.     return();
  695. }
  696.  
  697. CheckDriveGadgets()
  698. {
  699.     int c;
  700.     OnGadget(&df0gadget,Window,NULL);
  701.     OnGadget(&df1gadget,Window,NULL);
  702.     OnGadget(&df2gadget,Window,NULL);
  703.     OnGadget(&df3gadget,Window,NULL);
  704.     for (c=0;c<4;c++) {
  705.         error=OpenDevice("trackdisk.device",c,diskreq,0);
  706.         if (error!=0) {
  707.             switch (c) {
  708.                 case 0:
  709.                     OffGadget(&df0gadget,Window,NULL);
  710.                     break;
  711.                 case 1:
  712.                     OffGadget(&df1gadget,Window,NULL);
  713.                     break;
  714.                 case 2:
  715.                     OffGadget(&df2gadget,Window,NULL);
  716.                     break;
  717.                 case 3:
  718.                     OffGadget(&df3gadget,Window,NULL);
  719.                     break;
  720.                 default:
  721.                     break;
  722.             }
  723.         }
  724.         else CloseDevice(diskreq);
  725.     }
  726. }
  727.  
  728. CheckBlock(state)
  729. int state;
  730. {
  731.     nsbb[dnum]=0;
  732.     if (diskbuffer[8]=='C' &&
  733.             diskbuffer[9]=='H' &&
  734.             diskbuffer[10]=='W' &&
  735.             diskbuffer[11]=='!') nsbb[dnum]=2;
  736.     if (diskbuffer[43]=='9' &&
  737.             diskbuffer[44]=='.' &&
  738.             diskbuffer[45]=='8' &&
  739.             diskbuffer[46]=='7') nsbb[dnum]=3;
  740.     if (diskbuffer[192]=='D' &&
  741.             diskbuffer[193]=='A' &&
  742.             diskbuffer[194]=='S' &&
  743.             diskbuffer[195]=='A')    nsbb[dnum]=4;
  744.     if (diskbuffer[42]=='N' &&
  745.             diskbuffer[43]=='o' &&
  746.             diskbuffer[44]=='r' &&
  747.             diskbuffer[45]=='t') nsbb[dnum]=5;
  748.     if (diskbuffer[14]=='I' &&
  749.             diskbuffer[15]=='D' &&
  750.             diskbuffer[16]=='9') nsbb[dnum]=6;
  751.     if (diskbuffer[56]=='G' &&
  752.             diskbuffer[188]=='S' &&
  753.             diskbuffer[507]=='d' &&
  754.             diskbuffer[45]=='P') nsbb[dnum]=7;
  755.     if (diskbuffer[64]==0xff &&
  756.             diskbuffer[65]==0xa0 &&
  757.             diskbuffer[66]==0x20 &&
  758.             diskbuffer[67]==0x40)    nsbb[dnum]=8;
  759.     if (diskbuffer[368]==0xfe &&
  760.             diskbuffer[369]==0x3a &&
  761.             diskbuffer[370]==0x4c &&
  762.             diskbuffer[371]==0xdf) nsbb[dnum]=9;
  763.     if (diskbuffer[288]==0x33 &&
  764.             diskbuffer[289]==0xfc &&
  765.             diskbuffer[290]==0xf6 &&
  766.             diskbuffer[291]==0xd5) nsbb[dnum]=10;
  767.     if (diskbuffer[336]==0x66 &&
  768.             diskbuffer[337]==0x62 &&
  769.             diskbuffer[338]==0x48 &&
  770.             diskbuffer[339]==0xe7) nsbb[dnum]=11;
  771.     if (diskbuffer[112]==0x41 &&
  772.             diskbuffer[113]==0xfa &&
  773.             diskbuffer[114]==0x03 &&
  774.             diskbuffer[115]==0x5e) nsbb[dnum]=12;
  775.     if (diskbuffer[64]==0x03 &&
  776.             diskbuffer[65]==0x61 &&
  777.             diskbuffer[66]==0x34 &&
  778.             diskbuffer[67]==0x3c) nsbb[dnum]=13;
  779.     if (diskbuffer[464]==0x83 &&
  780.             diskbuffer[465]==0x35 &&
  781.             diskbuffer[466]==0x3e &&
  782.             diskbuffer[467]==0xf0) nsbb[dnum]=14;
  783.     if (point1[84]==0x000100bf) nsbb[dnum]=15;
  784.     if (point1[84]==0x3fff2c78) nsbb[dnum]=16;
  785.     if (point1[16]==0x4240323c) nsbb[dnum]=17;
  786.     if (point1[16]==0x0007ec1a) nsbb[dnum]=18;
  787.     if (nsbb[dnum]==0) return(TRUE);
  788.     if (state==1) return(FALSE);
  789.     CWindow=(struct Window *) OpenWindow(&WWindow);
  790.     Move(cprint,25,17);
  791.     Text(cprint,virusdesc[nsbb[c]],30);
  792.     Wait(1<<CWindow->UserPort->mp_SigBit);
  793.     nsbb[dnum]=0;
  794.     CloseWindow(CWindow);
  795.     return(TRUE);
  796. }
  797.  
  798. KillMemory()
  799. {
  800.     int temp;
  801.     struct ExecBase *ExecBase;
  802.     unsigned int *LongMemPointer, *ptr, x;
  803.     unsigned short *loc, *wordpointer;
  804.     unsigned long TD, *open, *entry, *oldopen;
  805.     char linebuffer[80];
  806.     char *a;
  807.     long *src, *dest, *vbase, *array;
  808.     int f,num;
  809.     UWORD *wordptr;
  810.     ExecBase=OpenLibrary("exec.library",0);
  811.     LongMemPointer=FindName(&ExecBase->DeviceList,"trackdisk.device");
  812.     array=4; array=array[0]; num=array; num=num-0x196;
  813.     open=num; entry=open[0]; oldopen=entry+0x12;
  814.     if (entry[0]=0x2f3a0010) {
  815.         open[0]=oldopen[0];
  816.         ExecBase->KickTagPtr=0;
  817.     }
  818.     temp=LongMemPointer;
  819.     temp=temp-0x1c;
  820.     LongMemPointer=temp;
  821.     VirusBase=(*LongMemPointer)-0x1b8;
  822.     LongMemPointer=VirusBase;
  823.     if (*LongMemPointer==ID_DOS_DISK) {
  824.  
  825.         #asm
  826.         xdef _VirusBase
  827.         xref _geta4
  828.         xref _LVODisable
  829.         xref _LVOEnable
  830.         jsr _geta4
  831.         move.l 4,a6
  832.         jsr _LVODisable(a6)
  833.         move.l _VirusBase,a0
  834.         move.w #$4e71,d0
  835.         move.w d0,$aa(a0)
  836.         move.w d0,$ac(a0)
  837.         move.w d0,$ae(a0)
  838.         move.w d0,$b0(a0)
  839.         move.w #$6000,$1c2(a0)
  840.         move.w #$6000,$2d2(a0)
  841.         move.w #$4e75,$388(a0)
  842.         move.w #0,(a0)
  843.         jsr _LVOEnable(a6)
  844.         #endasm
  845.  
  846.     };
  847.     TD=FindName(&ExecBase->DeviceList,"trackdisk.device");
  848.     x=TD; x=x-0x1c;
  849.     LongMemPointer=x; LongMemPointer=LongMemPointer[0];
  850.     x=LongMemPointer; x=x-0x17c;
  851.     LongMemPointer=x;
  852.     if (*LongMemPointer=ID_DOS_DISK) {
  853.         *LongMemPointer=0;
  854.         vbase=LongMemPointer;
  855.         Disable();
  856.         src=&vbase[234];
  857.         a=ExecBase; a=a-0x264;
  858.         dest=a; *dest=*src;
  859.         Enable();
  860.         ExecBase->KickTagPtr=0;
  861.     }
  862.     if (ExecBase->CoolCapture==0x7e060) {
  863.         ExecBase->CoolCapture=0;
  864.  
  865.         #asm
  866.         xref _LVODisable
  867.         xref _LVOEnable
  868.         move.l 4,a6
  869.         jsr _LVODisable(a6)
  870.         lea $7e000,a0
  871.         move.l #0,(a0)
  872.         move.w #$4ef9,$1e0(a0)
  873.         move.w #$7,$1e2(a0)
  874.         move.w #$e066,$1e4(a0)
  875.         move.w #$4ef9,$2da(a0)
  876.         move.w #$7,$2dc(a0)
  877.         move.w #$e06c,$2de(a0)
  878.         jsr _LVOEnable(a6)
  879.         #endasm
  880.  
  881.     };
  882.     if (ExecBase->CoolCapture==0x7ec64) {
  883.         ExecBase->CoolCapture=0;
  884.         x=ExecBase; x=x-0x1c6;
  885.         ptr=x;
  886.         LongMemPointer=0x7ef9c;
  887.         *ptr=*LongMemPointer;
  888.     }
  889.     wordpointer=ExecBase->CoolCapture;
  890.     if (*wordpointer==0x2c79) {
  891.         if (wordpointer[3]==0x203c) {
  892.             Disable();
  893.             f=ExecBase; f=f-0x1c6;
  894.             LongMemPointer=x;
  895.             wordpointer=*LongMemPointer;
  896.             f=wordpointer; f=f+0x15c;
  897.             wordpointer=f; *wordpointer=0x4e75;
  898.             f=wordpointer;
  899.             f=f+0x1e2;
  900.             wordpointer=f; *wordpointer=0x4e75;
  901.             f=ExecBase; f=f-0x1c6;
  902.             ptr=x;
  903.             f=*ptr; f=f+2;
  904.             LongMemPointer=f;
  905.             *ptr=*LongMemPointer;
  906.             Enable();
  907.         }
  908.     }
  909.     if (ExecBase->CoolCapture=0x7ed36) {
  910.         ExecBase->CoolCapture=0;
  911.         x=ExecBase;
  912.         x=x-0x1c6;
  913.         ptr=x;
  914.         wordptr=ptr;
  915.         if (wordptr[0]==0x0007) {
  916.             LongMemPointer=0x7eb38;
  917.             *ptr=*LongMemPointer;
  918.         }
  919.     }
  920.     if (ExecBase->CoolCapture==0x7e86c) {
  921.         ExecBase->CoolCapture=0;
  922.         ptr=0x7e88a;
  923.         Forbid();
  924.         ptr[0]=10;
  925.         Permit();
  926.     }
  927.     ExecBase->ColdCapture=0;
  928.     ExecBase->CoolCapture=0;
  929.     ExecBase->WarmCapture=0;
  930.     CloseLibrary(ExecBase);
  931.     return();
  932. }
  933.